package com.by.controller;

import com.by.bean.ForwardUser;
import com.by.bean.PageBean;
import com.by.bean.ResultBean;
import com.by.bean.User;
import com.by.group.ISave;
import com.by.group.IUpdate;
import com.by.group.V;
import com.by.mapper.UserMapper;
import com.by.query.ForwardUserQuery;
import com.by.service.ForwardUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * date 2025/2/17 20:51
 * author bjj
 * decoration
 * version 1.0
 * since jdk11
 */
@RestController
@RequestMapping("api")
@Api(tags = "货代管理")
public class ForwardUserController extends BaseController{
    @Autowired
    ForwardUserService forwardUserService;
    @Autowired
    UserMapper userMapper;

    @ApiOperation("保存货代信息")
    @PostMapping("/inquiry/save")
    public ResultBean save(@Validated(ISave.class) @RequestBody  ForwardUser forwardUser,BindingResult result){
        V.validate(result);
        int rs = forwardUserService.save(forwardUser);
        return saveResult(rs);
    }
    @ApiOperation("查询货代列表")
    @PostMapping("/inquiry/list")
    public ResultBean query(@RequestBody ForwardUserQuery query) {
        PageBean bean = forwardUserService.query(query);
        return success("客户列表", bean);
    }
    @ApiOperation("根据id查询货代信息")
    @GetMapping("/inquiry/queryById")
    public ResultBean queryById(@RequestParam int id){
        ForwardUser forwardUser = forwardUserService.get(id);
        if (forwardUser == null){
            return fail("客户信息不存在");
        }
        return success("客户信息",forwardUser);
    }

    @ApiOperation("保存用户")
    @PostMapping("/inquiry/user")
    public ResultBean save(@RequestBody User user){
        int rs = userMapper.save(user);
        return saveResult(rs);
    }
    @ApiImplicitParam(name = "id",value = "用户id",required = true)
    @ApiOperation("修改货代信息")
    @PostMapping("/inquiry/update")
    public ResultBean update(@RequestBody ForwardUser forwardUser){
        int rs = forwardUserService.update(forwardUser);
        return updateResult(rs);
    }
    @ApiImplicitParam(name = "id",value = "用户id",required = true)
    @ApiOperation("删除货代")
    @DeleteMapping("/inquiry/delete")
    public ResultBean delete(@RequestParam int id){
        int rs = forwardUserService.delete(id);
        return deleteResult(rs);
    }



}
